
cap program drop coefsv
program coefsv
		loc round `2'
		if "`round'" == "" loc round round
		foreach v in b? r? v? grtag se sewt b_?? s `round'0 coefrow {
			cap drop `v'
		}
		
		cap drop s
		gen s = e(sample)
		sort `round'
		levelsof `round' if s == 1, local(levels) 
		gen `round'0 = `round'
		loc n = 0
		loc dropomit = 0 //Do we drop round if omitted in regression? Switches to 1 after first omitted round
		gen coefrow = 0
		foreach l in `levels' {
			loc ++ n
			replace `round' = `l' if _n == `n'
			replace coefrow = 1 if _n == `n'
			if `dropomit' == 1 & _b[`l'.`round'] == 0 replace coefrow = 0 if _n == `n'
			if _b[`l'.`round'] == 0 loc dropomit 1 //After first omitted round, drop other omitted rounds.
		}
		
		predict b1 if coefrow == 1
		predict se if coefrow == 1, stdp
		
		replace `round' = `round'0
		
		reg date ibn.`round' if s, nocons
		matrix r = e(b)'

		svmat r
		
		replace b1 = . if _n > rowsof(r)
		replace b1 = . if b1 == b1[1] & _n != 1
		gen sewt = 1/se
		gen b_hi = b1 + 1.96*(se)
		gen b_lo = b1 - 1.96*(se)
end
